import request from '@api/request';
import { HttpUrl } from '@api/httpUrl';

// 获取客户列表
export function getSupplierList(available: boolean) {
    return request.get<AjaxResponse['supplierList']>(HttpUrl.getSupplierList, { params: { available } });
}

// 排序所有客户顺序
export function reorderSupplierPriority() {
    return request.get(HttpUrl.reorderSupplierPriority);
}

// 获取单个客户信息
export function getSupplierById(supplierId: string) {
    return request.get<AjaxResponse['supplierList'][0]>(HttpUrl.getSupplierById, { params: { supplierId } });
}

// 创建单个客户
export function createSupplier(supplierForm: AjaxRequest['supplierForm']) {
    return request.post(HttpUrl.createSupplier, { ...supplierForm });
}

// 导入客户
export function importSupplier(data: AjaxRequest['supplierForm'][]) {
    return request.post(HttpUrl.importSupplier, data);
}

// 拉取服务器保存供应商表.xlsx
export function pullSupplierList(pwd: string) {
    return request.get(HttpUrl.pullSupplierList, { params: { pwd } });
}

// 推送至服务器保存
export function pushSupplierList(data: AjaxResponse['supplierList'], pwd: string) {
    return request.post(HttpUrl.pushSupplierList, { data, pwd });
}

// 更新客户
export function updateSupplier(supplierData: AjaxRequest['updateSupplier']) {
    return request.put(HttpUrl.updateSupplier, { ...supplierData });
}

// 删除客户
export function deleteSupplier(ids: string[]) {
    return request.put(HttpUrl.deleteSupplier, { ids });
}
